Skip to content

Conversation

@Sanchoyzer
Copy link

Summary

I would like to suggest adding a little syntax sugar. It might be more convenient to use response.content_type instead of response.headers.get("Content-Type").
I hope I haven't forgotten any places where changes need to be made

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Sanchoyzer
Copy link
Author

Hey, @tomchristie , what do you think of this suggestion?

Return the Content-Type header.
"""
result = self.headers.get("Content-Type")
return str(result) if result else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the str() cast? Isn't it str already?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not str, it's Any

class Headers(typing.MutableMapping[str, str]):
    def get(self, key: str, default: typing.Any = None) -> typing.Any:
        ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, result defaults to None if the key is not present in the HTTP headers due to how the Headers.get function works, so you may as well return self.headers.get("Content-Type").

@Kludex
Copy link
Contributor

Kludex commented May 30, 2025

I think this is not needed, but we can see what other maintainers think about it.

@lovelydinosaur
Copy link
Contributor

what do you think of this suggestion?

I think this is not needed, but we can see what other maintainers think about it.

Indeed. Appreciate the interest tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants